package com.lvyerose.provinceandcity.provinceandcity.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lvyerose.provinceandcity.provinceandcity.R;

/**
 * author: lvyeRose
 * objective: 字母索引的适配器
 * mailbox: lvyerose@163.com
 * time: 15/6/29 22:15
 */
public class LetterAdapter extends BaseAdapter {
    private Context mContext;
    private String[] letter = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};

    //自定义字母集
    public LetterAdapter(Context mContext, String[] letter) {
        this.mContext = mContext;
        this.letter = letter;
    }
    //使用默认字母集A－Z
    public LetterAdapter(Context mContext) {
        this.mContext = mContext;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return letter.length;
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return letter[position];
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.letter_list, null);
        TextView tv = (TextView) view.findViewById(R.id.letterListTextView);
        tv.setText(letter[position]);
        return view;
    }

}
